package view.tablecellrenderer;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import view.RAMView;

import model.os.OS;
import model.os.Page;
import model.system.RAM;

public class RAMViewCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = -1723018259832157853L;

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		Component component = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);
		

		Color color = null;
		
		RAM ram = OS.getInstance().getRam();
		
		int frameNumber = row * RAMView.COLUMNS + column;
		
		Page page = ram.getPageFrames()[frameNumber];
		
		if (page != null) {
			color = page.getProcess().getColor();
		}
		
		component.setBackground(color);
		
		
		return component;
	}
	
}


